import 'package:spring_fairy/api/api.dart';
import 'package:http/http.dart' as http;

class FileUploadAPI extends API {
  ///上传文件,[path]文件路径
  Future<String?> uploadFile(String path) async {
    String url = "$HOST/upload/uploadFile";
    var request = http.MultipartRequest("POST",Uri.parse(url));
    request.files.add(
      await http.MultipartFile.fromPath(
        'file',
        path,
      )
    );
    request.headers['Cookie'] = API.token!;
    var response = await request.send();

    if(response.statusCode == 200) {
      return response.stream.bytesToString();
    } else {
      return null;
    }
  }
}